package com.i_art_engineer.meigong.net;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Base64;
import android.widget.Toast;

/**
 * Created by ming on 2016/4/6.
 */
public class NetUtil {

    public static String decodeURL(String base64url){
        byte[] d= Base64.decode(base64url,Base64.NO_WRAP);
        return new String(d);
    }
    public static final String baseurl = "http://www.9fanr.com/app/";
    public static final String url_checktoken =baseurl+ "account/auth";
    public static final String url_login =baseurl+  "";
    public static final String url_register =baseurl+  "account/signup";
    public static final String url_getcaptche =baseurl+  "sms/send";
    public static final String url_resetpwd =baseurl+  "";
    public static final String url_checkversion =baseurl+  "";
    public static final String url_firstpagepic =baseurl+  "";
    public static final String url_firstpagead =baseurl+  " ";
    public static final String url_tietu = baseurl+ "" ;
    public static final String url_watermark = baseurl+ "";
    public static final String url_works =baseurl+  "";
    public static final String url_personal = baseurl+ "";
    public static final String url_avatar = baseurl+ "";
    public static final String url_suggestion =baseurl+  "";
    public static final String url_logout =baseurl+  "";
    public static final String url_share = baseurl+ "";

    /**
     * 检查当前网络是否可用
     *
     * @param
     * @return
     */

    public static boolean isNetworkAvailable(Context activity)
    {
        Context context = activity.getApplicationContext();
        // 获取手机所有连接管理对象（包括对wi-fi,net等连接的管理）
        ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

        if (connectivityManager == null)
        {
            return false;
        }
        else
        {
            // 获取NetworkInfo对象
            NetworkInfo[] networkInfo = connectivityManager.getAllNetworkInfo();

            if (networkInfo != null && networkInfo.length > 0)
            {
                for (int i = 0; i < networkInfo.length; i++)
                {
                    System.out.println(i + "===状态===" + networkInfo[i].getState());
                    System.out.println(i + "===类型===" + networkInfo[i].getTypeName());
                    // 判断当前网络状态是否为连接状态
                    if (networkInfo[i].getState() == NetworkInfo.State.CONNECTED)
                    {
                        return true;
                    }
                }
            }
        }
        Toast.makeText(activity,"当前网络不通，请检查网络后重试！",Toast.LENGTH_SHORT).show();
        return false;
    }
}
